package com.wedding.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wedding.dao.ItemsMapper;
import com.wedding.dao.UserMapper;
import com.wedding.pojo.Items;
import com.wedding.pojo.ItemsExample;
import com.wedding.pojo.ItemsExample.Criteria;
import com.wedding.pojo.User;
import com.wedding.util.PageResult;

@Service
public class ItemsService {
	
	@Autowired
	private ItemsMapper itemsMapper;
	
	@Transactional
	public void testTransaction() {
		Items items = itemsMapper.selectByPrimaryKey(1);
		Items items2 = itemsMapper.selectByPrimaryKey(6);
//		int pic = itemsMapper.updateDecrePic(items, 100.00f);
		int i = 1/0;
//		int pic2 = itemsMapper.updateIncrePic(items2, 100.00f);
//		System.out.println(pic+"-"+pic2);
	}
	
	public void test2Transaction() {
		Items items = itemsMapper.selectByPrimaryKey(1);
		Items items2 = itemsMapper.selectByPrimaryKey(6);
//		int pic = itemsMapper.updateDecrePic(items, 100.00f);
		int i = 1/0;
//		int pic2 = itemsMapper.updateIncrePic(items2, 100.00f);
//		System.out.println(pic+"-"+pic2);
	}
	// 练习Mybatis分页插件PageHelper
	public PageInfo<Items> itemList(Integer pageNum, Integer pageSize) {
		ItemsExample example = new ItemsExample();
		Criteria criteria = example.createCriteria();
		
        PageHelper.startPage(pageNum, pageSize);
        List<Items> list = itemsMapper.selectByExample(null);
//        这是一种写法
//        Page<Items> page = (Page<Items>) itemsMapper.selectByExample(null);
//        List<Items> list = page.getResult();
//        这是另一种写法
        PageInfo<Items> pageInfo = new PageInfo<Items>(list);
        return pageInfo;
	}
	
}
